package com.openbravo.pos.panels;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.openbravo.bean.Product;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;

import java.awt.Dimension;

public class JProductDetailMini extends javax.swing.JPanel{
	private JTextField m_jName;
	private JTextField jMnemonic;
	private JTextField m_jRef;
	private JTextField m_jCode;
	private JTextField m_jPriceBuy;
	private JTextField m_jPriceSell;
	private JTextField m_jCustomerPrice;
	private JTextField jm_sManufacturer;
	private JTextField jm_origin;
	private JTextField jm_iDurability;
	private JTextField jm_quantity;
	private JTextField jm_unit;
	private JCheckBox m_jComment;


	public JProductDetailMini() {
		initComponents();
	}
	private void initComponents() {
		setPreferredSize(new Dimension(700, 130));
		setLayout(null);
		JLabel label = new JLabel();
		label.setText(AppLocal.getIntString("label.prodname"));
		label.setBounds(10, 13, 118, 15);
		add(label);

		m_jName = new JTextField();
		m_jName.setEditable(false);
		m_jName.setBounds(138, 10, 276, 21);
		add(m_jName);

		jMnemonic = new JTextField();
		jMnemonic.setEditable(false);
		jMnemonic.setBounds(412, 10, 69, 21);
		add(jMnemonic);

		JLabel label_1 = new JLabel();
		label_1.setText(AppLocal.getIntString("label.prodref"));
		label_1.setBounds(491, 13, 95, 15);
		add(label_1);

		m_jRef = new JTextField();
		m_jRef.setEditable(false);
		m_jRef.setBounds(596, 10, 80, 21);
		add(m_jRef);

		JLabel label_2 = new JLabel();
		label_2.setText(AppLocal.getIntString("label.prodbarcode"));
		label_2.setBounds(10, 41, 118, 15);
		add(label_2);

		m_jCode = new JTextField();
		m_jCode.setEditable(false);
		m_jCode.setBounds(138, 38, 110, 21);
		add(m_jCode);

		JLabel label_3 = new JLabel();
		label_3.setText(AppLocal.getIntString("label.prodpricebuy"));
		label_3.setBounds(491, 41, 95, 15);
		add(label_3);

		m_jPriceBuy = new JTextField();
		m_jPriceBuy.setEditable(false);
		m_jPriceBuy.setHorizontalAlignment(SwingConstants.RIGHT);
		m_jPriceBuy.setBounds(596, 38, 80, 21);
		add(m_jPriceBuy);

		JLabel label_4 = new JLabel();
		label_4.setText(AppLocal.getIntString("label.prodpricesell"));
		label_4.setBounds(491, 72, 95, 15);
		add(label_4);

		m_jPriceSell = new JTextField();
		m_jPriceSell.setEditable(false);
		m_jPriceSell.setHorizontalAlignment(SwingConstants.RIGHT);
		m_jPriceSell.setBounds(596, 69, 80, 21);
		add(m_jPriceSell);

		JLabel label_5 = new JLabel();
		label_5.setText(AppLocal.getIntString("label.baseCustomerPrice"));
		label_5.setBounds(491, 105, 95, 15);
		add(label_5);

		m_jCustomerPrice = new JTextField();
		m_jCustomerPrice.setEditable(false);
		m_jCustomerPrice.setHorizontalAlignment(SwingConstants.RIGHT);
		m_jCustomerPrice.setBounds(596, 102, 80, 21);
		add(m_jCustomerPrice);

		JLabel label_6 = new JLabel();
		label_6.setText(AppLocal.getIntString("label.prodcut.m_sManufacturer"));
		label_6.setBounds(10, 69, 118, 20);
		add(label_6);

		jm_sManufacturer = new JTextField();
		jm_sManufacturer.setEditable(false);
		jm_sManufacturer.setBounds(138, 69, 110, 21);
		add(jm_sManufacturer);

		JLabel label_7 = new JLabel();
		label_7.setText(AppLocal.getIntString("label.product.origin"));
		label_7.setBounds(258, 69, 80, 20);
		add(label_7);

		jm_origin = new JTextField();
		jm_origin.setEditable(false);
		jm_origin.setHorizontalAlignment(SwingConstants.CENTER);
		jm_origin.setBounds(348, 69, 110, 21);
		add(jm_origin);

		JLabel label_8 = new JLabel();
		label_8.setText(AppLocal.getIntString("label.product.m_iDurability"));
		label_8.setBounds(10, 102, 118, 20);
		add(label_8);

		jm_iDurability = new JTextField();
		jm_iDurability.setEditable(false);
		jm_iDurability.setHorizontalAlignment(SwingConstants.CENTER);
		jm_iDurability.setBounds(138, 102, 110, 21);
		add(jm_iDurability);
		
		jm_quantity = new JTextField();
		jm_quantity.setEditable(false);
		jm_quantity.setHorizontalAlignment(SwingConstants.RIGHT);
		jm_quantity.setBounds(258, 38, 92, 21);
		add(jm_quantity);
		
		jm_unit = new JTextField();
		jm_unit.setEditable(false);
		jm_unit.setHorizontalAlignment(SwingConstants.CENTER);
		jm_unit.setBounds(385, 38, 80, 21);
		add(jm_unit);
		
		JLabel label_9 = new JLabel();
		label_9.setText(AppLocal.getIntString("label.prodaux"));
		label_9.setBounds(258, 105, 101, 15);
		add(label_9);

		m_jComment = new JCheckBox();
		m_jComment.setEnabled(false);
		m_jComment.setBounds(376, 102, 80, 21);
		add(m_jComment);
	}
    
	private Product obj;
	public void detailProduct(Product obj){
		this.obj=obj;
		 if(obj!=null){
		        m_jRef.setText(obj.getReference());
		        m_jCode.setText(Formats.STRING.formatValue(obj.getCode()));
		        m_jName.setText(Formats.STRING.formatValue(obj.getName()));
		        m_jComment.setSelected(obj.isCom());
		        jm_origin.setText(Formats.STRING.formatValue(obj.getM_origin()));
		        jm_quantity.setText(Formats.DOUBLE.formatValue(obj.getM_quantity()));
		        jm_unit.setText(Formats.STRING.formatValue(obj.getM_unit()));
		        jm_sManufacturer.setText(Formats.STRING.formatValue(obj.getM_sManufacturer()));
		        jm_iDurability.setText(Formats.INT.formatValue(obj.getM_iDurability()));
		        jMnemonic.setText(Formats.STRING.formatValue(obj.getMnemonic()));
		        m_jPriceBuy.setText(Formats.CURRENCY.formatValue(obj.getPriceBuy())); 
		        m_jPriceSell.setText(Formats.CURRENCY.formatValue(obj.getPriceSell()));
		        m_jCustomerPrice.setText(Formats.CURRENCY.formatValue(obj.getM_dCustomerPrice())); 
			 }else{
				    m_jRef.setText(null);
			        m_jCode.setText(null);
			        m_jName.setText(null);
			        m_jComment.setSelected(false);
			        jm_origin.setText(null);
			        jm_quantity.setText(null);
			        jm_unit.setText(null);
			        jm_sManufacturer.setText(null);
			        jm_iDurability.setText(null);
			        jMnemonic.setText(null);
			        m_jPriceBuy.setText(null);
			        m_jPriceSell.setText(null);
			        m_jCustomerPrice.setText(null);
			 }
	}
	public Product getObj() {
		return obj;
	}
	public void setObj(Product obj) {
		this.obj = obj;
	}
}
